package b3.widget.vip
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.widget.basic.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;

	public class VipDailyGiftDialog extends BasicWidget
	{
		private const dailyPresents:Array = ["323_1", "323_2", "323_3", "323_3,303_1", "323_3,303_2", "323_3,303_3", "323_4,303_3", "323_4,303_4"];
		
		public function VipDailyGiftDialog()
		{
			super();
			//对话框背景
			var VipNewPlayerDialogBgr:Class = ResourceHelper.getInstance().getClassByName("VipDailyGiftDialogBgr");
			addChild(new VipNewPlayerDialogBgr());
			//关闭按钮
			var VipButtonClose1:Class = ResourceHelper.getInstance().getClassByName("VipButtonClose1");
			var VipButtonClose2:Class = ResourceHelper.getInstance().getClassByName("VipButtonClose2");
			var closeIcon:ImgSwitchIcon = new ImgSwitchIcon(VipButtonClose1, VipButtonClose2);
			closeIcon.x = 560;
			closeIcon.y = 15;
			addChild(closeIcon);
			closeIcon.addEventListener(MouseEvent.CLICK, onButtonCloseClick);
			var me:Player = PlayerManager.getInstance().me;
			var presentContainer:Sprite = new Sprite();
			//当前礼物
			var dailyPresent:Array = dailyPresents[me.yellow_vip_level - 1].split(",");
			for (var i:int = 0; i < dailyPresent.length; i++)
			{
				var presentStr:Array = dailyPresent[i].split("_");
				var objectIndex:int = presentStr[0];
				var objectNum:int = presentStr[1];
				var giftItem:Sprite = getGiftItem(objectIndex, objectNum, !(me.is_yellow_vip || me.is_yellow_year_vip))
				giftItem.x = 140 * i;
				presentContainer.addChild(giftItem);
			}
			presentContainer.x = 165 - presentContainer.width / 2;
			presentContainer.y = 200;
			addChild(presentContainer);
			//年费礼物
			giftItem = getGiftItem(318, 1, !me.is_yellow_year_vip)
			giftItem.x = 400;
			giftItem.y = 200;
			addChild(giftItem);
			//底部
			var bottomTitleText:TextField = new TextField();
			bottomTitleText.selectable = false;
        	bottomTitleText.autoSize = TextFieldAutoSize.LEFT;
			bottomTitleText.defaultTextFormat = new TextFormat("微软雅黑", 14, 0xA77E5C);
			bottomTitleText.width = 200;
			bottomTitleText.text = "领取奖励后您将在包裹道具栏中找到！";
			bottomTitleText.x = (this.width - bottomTitleText.width) / 2;
			bottomTitleText.y = 360;
			addChild(bottomTitleText);
			//顶部
			//礼物价值
			var vipPriceText:TextField = new TextField();
			vipPriceText.selectable = false;
        	vipPriceText.autoSize = TextFieldAutoSize.CENTER;
        	vipPriceText.defaultTextFormat = new TextFormat("微软雅黑", 16, 0xF9F744, true);
			vipPriceText.filters = [new GlowFilter(0x8F470E, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			vipPriceText.x = 168;
			vipPriceText.y = 150;
			vipPriceText.text = (30 * me.yellow_vip_level).toString();
			addChild(vipPriceText);
			//年费礼物价值
			var yearVipPriceText:TextField = new TextField();
			yearVipPriceText.selectable = false;
        	yearVipPriceText.autoSize = TextFieldAutoSize.CENTER;
        	yearVipPriceText.defaultTextFormat = new TextFormat("微软雅黑", 16, 0xF9F744, true);
			yearVipPriceText.filters = [new GlowFilter(0x8F470E, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			yearVipPriceText.x = 452;
			yearVipPriceText.y = 150;
			yearVipPriceText.text = (70).toString();
			addChild(yearVipPriceText);
			
			var vipTitleText:TextField = new TextField();
			vipTitleText.selectable = false;
        	vipTitleText.autoSize = TextFieldAutoSize.LEFT;
			vipTitleText.defaultTextFormat = new TextFormat("微软雅黑", 20, 0x8F470E, true);
			vipTitleText.x = 112;
			vipTitleText.y = 95;
			addChild(vipTitleText);
			if (me.is_yellow_vip || me.is_yellow_year_vip)
			{
				vipTitleText.text = "您是黄钻贵族";
				//续费黄钻
				var vipButtonResume:VipButtonResume = new VipButtonResume();
				vipButtonResume.x = 105;
				vipButtonResume.y = 300;
				addChild(vipButtonResume);
			}
			var yearVipTitleText:TextField = new TextField();
			yearVipTitleText.selectable = false;
        	yearVipTitleText.autoSize = TextFieldAutoSize.LEFT;
			yearVipTitleText.defaultTextFormat = new TextFormat("微软雅黑", 20, 0x8F470E, true);
			yearVipTitleText.x = 390;
			yearVipTitleText.y = 95;
			addChild(yearVipTitleText);
			if (me.is_yellow_year_vip)
			{
				yearVipTitleText.text = "您是年费黄钻贵族";
			}
			else
			{
				yearVipTitleText.text = "成为年费黄钻贵族";
			}
			//续费黄钻年费
			var vipButtonYear:VipButtonOpenYear = new VipButtonOpenYear();
			vipButtonYear.x = 370;
			vipButtonYear.y = 300;
			addChild(vipButtonYear);
			//立即领取
			var VipButtonFetch:Class = ResourceHelper.getInstance().getClassByName("VipButtonFetch");
			var fetchButton:BasicButton = new BasicButton(VipButtonFetch);
			fetchButton.x = (this.width - fetchButton.width) / 2;
			fetchButton.y = 400;
			fetchButton.addEventListener(MouseEvent.CLICK, onButtonFectchClick);
			addChild(fetchButton);
			this.anchor = BasicWidget.ANCHOR_MIDDLE_MIDDLE;
			this.x = - this.width / 2;
			this.y = - this.height / 2;
		}
		
		private function getGiftItem(objectIndex:int, objectNum:int, lockFlag:Boolean):Sprite
		{
			var giftItem:Sprite = new Sprite();
			var objectConfig:ObjConfig = Config.objConfigs[objectIndex];
			var ObjectImage:Class = ResourceHelper.getInstance().getClassByName(objectConfig.iconImage[0]);
			var objectItem:Sprite = new ObjectImage();
			objectItem.width = 82;
			objectItem.scaleY = objectItem.scaleX;
			objectItem.x = 0;
			giftItem.addChild(objectItem);
			//个数名字
			var numText:TextField = new TextField();
			numText.selectable = false;
        	numText.autoSize = TextFieldAutoSize.LEFT;
        	numText.defaultTextFormat = new TextFormat("微软雅黑", 20, 0xF9F744, true, true);
			numText.text = "× " + objectNum + " ";
			numText.filters = [new GlowFilter(0x8F470E, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			numText.x = 80;
			numText.y = 25;
			giftItem.addChild(numText);
			//锁
			if (lockFlag)
			{
				var VipLock:Class = ResourceHelper.getInstance().getClassByName("VipLock");
				var lock:Sprite = new VipLock();
				lock.width = 40;
				lock.scaleY = lock.scaleX;
				lock.x = - 10;
				lock.y = -20;
				giftItem.addChild(lock);
			}
			giftItem.mouseChildren = false;
			return giftItem;
		}
		
		private function onButtonFectchClick(event:MouseEvent):void
		{
			var me:Player = PlayerManager.getInstance().me;
			me.fetchVipDailyPresent();
			close();
		}
		
		private function onButtonCloseClick(event:MouseEvent):void
		{
			close();
		}
		
	}
}